<?php

/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */
require_once 'Model/User_Model.php';

/**
 * Index Controller
 */
class Index extends Controller {

    /**
     * Create index
     */
    function __construct() {
        if (Session::Get(Constants::$SESSION_cuser) == NULL) {
            Session::Destroy();
            header('location: '. $GLOBALS['conf']['interface']['url'] .'login');
            exit;
        }
        parent::__construct();
    }

    /**
     * @see Controller
     */
    protected function _Init() {
        parent::_Init();
    }

    /**
     * @see Controller
     */
    function Update() {
        parent::Update();
    }
    
    /**
     * Add an user
     */
    function nuser(){
        $this->model->nuser();
    }
    
    /**
     * Delete user(s)
     */
    function duser(){
        $this->model->duser();
    }

    /**
     * Delete Database(s)
     */
    function ddatabase(){
        $this->model->ddatabase();
    }
    
    /**
     * Add a database
     */
    function ndatabase(){
        $this->model->ndatabase();
    }
    
    /**
     * Sent request
     */
    function nrequete() {
        $this->model->nRequete();
    }
    
    /**
     * Updat user password
     */
    function UserPwd(){
        $this->model->UserPwd();
    }
    
    /**
     * Select a database
     */
    function SelectDB(){
        $this->model->SelectDB();
    }

    /**
     * Destroy all interface sessions and redirect login page
     */
    function Logout() {
        $chk = new User_Model();
        $chk->User_Log(Session::Get(Constants::$SESSION_cuser), $_SERVER["REMOTE_ADDR"], 'D&eacute;connexion de l\'interface');
        Session::Destroy();
        header('location: '. $GLOBALS['conf']['interface']['url'] .'login');
        exit;
    }
    
    /**
     * Destroy all interface sessions and redirect login page
     */
    function Home() {
        Session::Destroy(Constants::$SESSION_cdb);
        Session::Destroy(Constants::$SESSION_ldb);
        Session::Destroy(Constants::$SESSION_pdb);
        header('location: '. $GLOBALS['conf']['interface']['url']);
        exit;
    }

}